
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js"><!--<![endif]-->
<head>
  <meta charset="utf-8">
  <title>
    
  Nginx的启动、停止与重启 - LZH-DEV-TECH-SHARE
  

  </title>
  <meta name="author" content="">
  <meta name="description" content="">

  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <link href="asset/css/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
  <link href="atom.xml" rel="alternate" title="LZH-DEV-TECH-SHARE" type="application/atom+xml">
  <script src="asset/js/modernizr-2.0.js"></script>
  <script src="asset/js/jquery.min.js"></script>
  <script src="asset/highlightjs/highlight.pack.js"></script>
  <link href="asset/highlightjs/styles/solarized_light.css" media="screen, projection" rel="stylesheet" type="text/css">
  <script>hljs.initHighlightingOnLoad();</script>

  <style type="text/css">
  .cat-children-p{ padding: 6px 0px;}
  .hljs{background: none;}
  </style>
  <script type="text/javascript">
  var isAddSildbar = true;
  </script>
  <script src="asset/js/octopress.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
//链接新开窗口
function addBlankTargetForLinks () {
  $('a[href^="http"]').each(function(){
      $(this).attr('target', '_blank');
  });
}
$(document).ready(function(event) {
  addBlankTargetForLinks();
});
</script>
<body   >
  <header role="banner"><hgroup>
  <h1><a href="index.html">LZH-DEV-TECH-SHARE</a></h1>
  
    <h2></h2>
  
</hgroup>

</header>
  <nav role="navigation"><ul class="subscription" data-subscription="rss">
  <li><a href="atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
  
</ul>
  
<form action="http://google.com/search" method="get">
  <fieldset role="search">
    <input type="hidden" name="q" value="site:" />
    <input class="search" type="text" name="q" results="0" placeholder="Search"/>
  </fieldset>
</form>
  
<ul class="main-navigation">

  <li id=""><a target="self" href="index.html">Home</a></li>

  <li id=""><a target="_self" href="archives.html">Archives</a></li>

</ul>

</nav>
  <div id="main">
    <div id="content"> 
<div>
	<article class="hentry" role="article">
	<header>
			  	<h1 class="entry-title">Nginx的启动、停止与重启</h1>
				<p class="meta"><time datetime="2018-10-23T19:44:45+08:00" pubdate data-updated="true">2018/10/23</time></p>
			 </header>
		  	<div class="entry-content">
			  	<ul>
<li>
<a href="#toc_0">启动</a>
</li>
<li>
<a href="#toc_1">停止</a>
<ul>
<li>
<a href="#toc_2">从容停止</a>
</li>
<li>
<a href="#toc_3">快速停止</a>
</li>
<li>
<a href="#toc_4">强制停止</a>
</li>
</ul>
</li>
<li>
<a href="#toc_5">重启</a>
</li>
</ul>


<h2 id="toc_0">启动</h2>

<p>启动代码格式：nginx安装目录地址 -c nginx配置文件地址</p>

<p>例如：</p>

<pre><code class="language-shell">[root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
</code></pre>

<h2 id="toc_1">停止</h2>

<p>nginx的停止有三种方式：</p>

<h3 id="toc_2">从容停止</h3>

<p>　　1、查看进程号</p>

<pre><code class="language-shell">[root@LinuxServer ~]# ps -ef|grep nginx
</code></pre>

<p><img src="media/15402950858118/15402954030895.jpg" alt=""/></p>

<p>　　2、杀死进程</p>

<pre><code class="language-shell">[root@LinuxServer ~]# kill -QUIT 2072
</code></pre>

<p><img src="media/15402950858118/15402954134920.jpg" alt=""/></p>

<h3 id="toc_3">快速停止</h3>

<p>1、查看进程号</p>

<pre><code class="language-shell">[root@LinuxServer ~]# ps -ef|grep nginx
</code></pre>

<p><img src="media/15402950858118/15402954229262.jpg" alt=""/></p>

<p>2、杀死进程</p>

<pre><code class="language-shell">[root@LinuxServer ~]# kill -TERM 2132
</code></pre>

<p>或 </p>

<pre><code class="language-shell">[root@LinuxServer ~]# kill -INT 2132
</code></pre>

<p><img src="media/15402950858118/15402954314580.jpg" alt=""/></p>

<h3 id="toc_4">强制停止</h3>

<pre><code class="language-shell">[root@LinuxServer ~]# pkill -9 nginx
</code></pre>

<h2 id="toc_5">重启</h2>

<ul>
<li>验证nginx配置文件是否正确</li>
</ul>

<p>方法一：进入nginx安装目录sbin下，输入命令</p>

<pre><code class="language-shell">./nginx -t
</code></pre>

<p>看到如下显示</p>

<pre><code class="language-shell">nginx.conf syntax is ok

nginx.conf test is successful
</code></pre>

<p>说明配置文件正确！</p>

<p><img src="media/15402950858118/15402954436521.jpg" alt=""/></p>

<p>方法二：在启动命令-c前加-t<br/>
<img src="media/15402950858118/15402954542875.jpg" alt=""/></p>

<ul>
<li><p>重启Nginx服务<br/>
方法一：进入nginx可执行目录sbin下，输入命令</p>
<pre><code class="language-shell">./nginx -s reload
</code></pre>
<p>即可<br/>
<img src="media/15402950858118/15402954645283.jpg" alt=""/></p></li>
</ul>

<p>方法二：查找当前nginx进程号，然后输入命令：</p>

<pre><code class="language-shell">kill -HUP 进程号 
</code></pre>

<p>实现重启nginx服务<br/>
<img src="media/15402950858118/15402954740748.jpg" alt=""/></p>

			</div>

		
	  
		<footer>
		 <p class="meta">

			<strong>Categories:</strong>&nbsp; 
			<span class="categories">
			
			    <a class='category' href='back-end.html'>back-end</a>&nbsp;
			 
			</span>
		    </p>
		    <p class="meta">
		      
		 </p>
	    
		<div class="sharing">
		  
          

          

		</div>

	    <p class="meta">
	    
	        <a class="basic-alignment left" href="15403770118414.html" 
	        title="Previous Post: Git Workflow 工作指南">&laquo; Git Workflow 工作指南</a>
	    
	    
	        <a class="basic-alignment right" href="15397707900555.html" 
	        title="Next Post: Markdown简明语法教程">Markdown简明语法教程 &raquo;</a>
	    
	    </p>
	  </footer>
	</article>
</div>
 <aside class="sidebar"> 

	<section>
	  <h1>Categories</h1>
	  <ul id="recent_posts">
	  
	      <li class="post">
	        <a href="version-control.html"><strong>version-control&nbsp;(2)</strong></a>
	        
	        
	        
	      </li>
	  
	      <li class="post">
	        <a href="shell.html"><strong>shell&nbsp;(1)</strong></a>
	        
	        
	        
	      </li>
	  
	      <li class="post">
	        <a href="back-end.html"><strong>back-end&nbsp;(4)</strong></a>
	        
	        
	        
	      </li>
	  
	      <li class="post">
	        <a href="front-end.html"><strong>front-end&nbsp;(5)</strong></a>
	        
	        
	        
	      </li>
	  
	      <li class="post">
	        <a href="version-control-1.html"><strong>version-control&nbsp;(1)</strong></a>
	        
	        
	        
	      </li>
	  
	      <li class="post">
	        <a href="other.html"><strong>other&nbsp;(2)</strong></a>
	        
	        
	        
	      </li>
	   
	  </ul>
	</section>
	<section>
	  <h1>Recent Posts</h1>
	  <ul id="recent_posts">
	  
	      
		      <li class="post">
		        <a href="15413898294420.html">RESTful API 最佳实践</a>
		      </li>
	     
	  
	      
		      <li class="post">
		        <a href="15411425055347.html">LZH-DEV-GROUP Git Workflow 实践详解</a>
		      </li>
	     
	  
	      
		      <li class="post">
		        <a href="15410718240579.html">如何使用PM2进程管理器, 守护java进程</a>
		      </li>
	     
	  
	      
		      <li class="post">
		        <a href="15408811446857.html">一篇文章搞定 centos7 上的 mysql 安装</a>
		      </li>
	     
	  
	      
		      <li class="post">
		        <a href="15408703788547.html">一篇文章搞定 centos7 下安装 nvm和node</a>
		      </li>
	     
	  
	      
	  
	      
	  
	      
	  
	      
	  
	      
	  
	      
	  
	      
	  
	      
	  
	      
	  
	      
	   
	  </ul>
	</section>
	
</aside> </div></div>
  <footer role="contentinfo"><p>
  Copyright &copy; 2014 -  -
  <span class="credit">Powered by <a target="_blank" href="http://www.mweb.im">MWeb</a> &nbsp;&nbsp; Theme by <a href="http://octopress.org">Octopress</a></span>
</p>

</footer>

  
    




</body>
</html>